package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.SuiteBiz;
import guda.stark.dal.dao.SuiteDAO;
import guda.stark.dal.dataobject.SuiteDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class SuiteBizImpl implements SuiteBiz{

    private final static Logger logger = LoggerFactory.getLogger(SuiteBizImpl.class);

    @Autowired
    private SuiteDAO suiteDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            SuiteDO suiteDO = suiteDAO.getSuiteById(id);
            bizResult.data.put("suiteDO", suiteDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query Suite error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = suiteDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<SuiteDO> suiteList = suiteDAO.selectForPage(baseQuery);
            bizResult.data.put("suiteList", suiteList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view Suite list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            suiteDAO.delSuiteById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete suite error", e);
        }
        return bizResult;
    }

    public BizResult create(SuiteDO suiteDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = suiteDAO.insert(suiteDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create Suite error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(SuiteDO suiteDO) {
        BizResult bizResult = new BizResult();
        try {
            suiteDAO.updateByIdSelective(suiteDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update Suite error", e);
        }
        return bizResult;
    }


}
